// pages/home/product/preproduct/preproduct.js
const globalIp = getApp().globalData.userIp
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list: [],
    pageIndex:1,
    pageSize:20,
    total: 0,
    IndexList: [],
    popup: false
  },

  getInputValue() {
    wx.navigateTo({
      url: './preproductSearch/preproductSearch',
    })
  },

  clickTap(e){
    this.setData({
      popup: true
    })
    let that = this;
    wx.showLoading({
      title: '数据加载中...',
    })
    wx.request({
      url: globalIp + 'home/oitm/preProduct',
      data: {
        openId: wx.getStorageSync('userInfo')?wx.getStorageSync('userInfo').openid:'',
        value: 2,
        cardCode: e.currentTarget.dataset.code,
        pageIndex: 0,
        pageSize: 0 
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      success: function(res) {
        that.setData({
          IndexList: res.data.jsonObject.data
        })
      },
      complete: () => {
        wx.hideLoading()
      }
    })
  },

  clickTapClose(){
    this.setData({
      popup: false,
      IndexList: []
    })
  },

  allShow: function(){
    var that = this;
    wx.showLoading({
      title: '数据加载中...',
    })
    wx.request({
      url: globalIp + 'home/oitm/preProduct',
      data: {
        pageSize: this.data.pageSize,
        pageIndex: this.data.pageIndex,
        value: 1,
        openId: wx.getStorageSync('userInfo').openid
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      success: function(res) {
        that.setData({
          total: that.data.total + res.data.total,
          list: [...that.data.list, ...res.data.jsonObject.data]
        })
      },
      complete: () => {
        wx.hideLoading()
      }
    })
  },

  selectShow(e) {
    wx.navigateTo({
      url: './preproductIndex/preproductIndex?CardCode='+e.currentTarget.dataset.code
      +'&type='+e.currentTarget.dataset.type,
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    // 页面渲染完成
    this.allShow()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.setData({
      pageIndex: this.data.pageIndex + 1
    })
    this.allShow()
  },

})